package com.ixoko.swagger.controller.global;

import com.alibaba.fastjson.JSON;
import com.ixoko.swagger.util.HttpClientUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;

/**
 * @author luojie
 * @Date 2018/7/28
 */
@Api(description = "公共接口")
@RestController
@RequestMapping("/tourism/glob")
public class GlobalController {

    @Value("${http.client.base.url}")
    private String baseUrl;

    @RequestMapping(value = "/rongCloud/token")
    @ApiOperation(value = "融云获取token接口", httpMethod = "POST", produces = "*/*", consumes = "*/*")
    @ApiImplicitParam(name = "id", value = "不传获取自己的融云token 传获取其他人的token 用户userId")
    public String rongCloud(Long userId) throws IOException, ExecutionException {
        String url = baseUrl + "/glob/rongCloud/token";
        HashMap<String, Long> hashMap = new HashMap<>();
        hashMap.put("userId", userId);
        String post = HttpClientUtil.post(url, JSON.toJSONString(hashMap));
        return post;
    }


}
